<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2024/5/28
 * Time: 16:52
 */

namespace app\controller\admin;


use app\model\News;
use think\facade\Db;

class Message extends Base
{
    public function list(){
        $news = new News();
        $list = $news->paginate(['page' => $this->page,'list_rows' => $this->size]);
        return $this->view('/admin/message/list',['list' => $list]);
    }

    public function info(){
        $id = input('id');
        $find = (new News())->where('id',$id)->find();
        return $this->view('/admin/message/info',['info' => $find ?? [],'id' => $id ?? 0]);
    }

    public function save(){
        $id = input('id');
        $news = new News();
        $post = input('post.');
        if (!empty($id)){
            $news->where('id',$id)->save($post);
        }else{
            $news->save($post);
        }
        return $this->msg();
    }

    public function delete($id){
        $ids = input('ids');
        if (!empty($ids)){
            News::where('id','IN',$ids)->delete();
        }else {
            News::find($id)->delete();
        }
        return $this->msg();
    }
}